<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>">
		<title>用户登录</title>
		<link href="skin/default/style.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript"
			src="<%=basePath%>js/jquery-1.7.2.min.js">
</script>
		<script type="text/javascript">
$(function() {
	//max 屏幕
	maxedPage();
	
	$("#userName").focus();
	$("#userName").blur(function() {
		var userName = $("#userName").val();
		if (userName == "") {
			//alert("用户名不能为空");
			$("#userName").focus();
		}
	});
});
function keyDown(event){
    if(event.keyCode==13){   
		login();
	}   
}


function matchUser(){
	var pattren=/^[a-zA-Z]{1}[0-9a-zA-Z_]{1,}$/;
	var pattren2=/^[0-9a-zA-Z_]{1,}$/;
	var sNo  = $("#userName").val();
	var sPwd = $("#pwd").val();
	if(!sNo.match(pattren)){
		$("#message").html("用户名只能用字母、数字、下划线组成.首字母不能数字开头！");
		return false;	
	}
	if(!sPwd.match(pattren2)){
		$("#message").html("密码只能用字母、数字、下划线组成！");
		return false;	
	}
	return true;
}

function login() {
	var sNo  = $("#userName");  //用户名
	var sPwd = $("#pwd");       //密码 
	if(sNo.val().length>15||sPwd.val().length>15){
		$("#message").html("用户名或密码太长，请重新输入！");
		sNo.attr("value","");
		sPwd.attr("value","");
		sNo.focus();
		return false;
	}
	else if(sNo.val()==""||sPwd.val()==""){
		$("#message").html("用户名或密码不能为空!");
		sNo.focus();
		return false;
	}
	//当用户名，密码不为空 验证合法性
	if(!matchUser()){
		return false;
	}
	var params = $("input").serialize();
	$.ajax( {
		url : "logon_execute.action",
		type : "POST",
		data : params,
		dataType : "json",
		success : function(data) {
			if (data.message != null)
				$("#message").html(data.message);
			else {
				//是否存在登录前的uri 若存在跳转到登录前的uri
				var url = "index.jsp";
				if (data.requestUri != null)
					url = data.requestUri;
				window.location.href=url;
			}
	},
	error:function(msg){
		alert(msg.responseText);}
	});
}

function maxedPage()
{
   ReSizePage(screen.availWidth, screen.availHeight);
}

function ReSizePage(width, height)
{
   var aw = screen.availWidth; 
   var ah = screen.availHeight; 
	var xc = (aw - width) / 2; 
	var yc = (ah - height) / 2;
    self.moveTo(xc, yc);
	self.resizeTo(width, height);
	    
}





</script>
	</head>

	<body id="login">
<div id="login-wrapper" class="png_bg">
			<div id="login-top">
			</div>
			<div id="login-content">
					<div class="notification information png_bg">
						<div>
							<span id="message" style="font-size:20px;color:red;"></span>
						</div>
					</div>
					<p>
						<label>用户名</label>
                        <input class="text-input" id="userName" name="user.no" type="text" />
					</p>
					<p>
						<label>密&nbsp;&nbsp;码</label>
                        <input class="text-input" id="pwd" name="user.password" type="password"  onKeyDown="keyDown(event);"/>
					</p>
					<p>
						<input class="button" type="button" id="login" value=" " onclick="login()"/>
					</p>
			</div>
			
		</div>
	</body>
</html>
